﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace Grauers.SharePointGoogleChart
{
    public class DiagramHelper
    {
        public static SPListItemCollection GetListItems(string listUrl, string listView)
        {
            SPListItemCollection listCollection = null;
            if (listUrl != null && listUrl.Length > 0)
            {
                SPSite site = new SPSite(listUrl);
                SPWeb web = site.OpenWeb();

                SPList list = web.GetListFromUrl(listUrl);
                SPView view;

                if (listView == null || listView.Length == 0)
                    view = list.DefaultView;
                else
                    view = list.Views[listView];

                SPQuery query = new SPQuery();
                query.Query = view.Query;
                listCollection = list.GetItems(query);
            }

            return listCollection;

        }
        
    }
}
